package common.dtos;

import common.entity.book.BookInfo;
import common.entity.book.GoodInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 郑国荣
 * @Date: 2024-04-03-17:08
 * @Description:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GoodHomePageDto {
    private int goodId;
    private int bookId;
    private BookInfo bookInfo;
    private GoodInfo goodInfo;

    public List<GoodHomePageDto> mergeBookInfo(List<BookInfo> bookInfos,List<GoodInfo> goodInfos){
        List<GoodHomePageDto> goodHomePageDtos = new ArrayList<>();
        for (BookInfo bookInfo : bookInfos) {
            for (GoodInfo goodInfo : goodInfos) {
                if (bookInfo.getBookId() == goodInfo.getBookId()){
                    goodHomePageDtos.add(new GoodHomePageDto(goodInfo.getGoodId(),goodInfo.getBookId(),bookInfo,goodInfo));
                }
            }
        }
        return goodHomePageDtos;
    }
}
